// var ApiBaseUrl = 'https://eper-api.cctv8.co/eper-api';
// var ApiUrl = 'http://demo-dev.cctv8.co/eper-api';
// var ApiBaseUrl = 'http://localhost:8081/eper-api';

//var ApiBaseUrl = 'https://eper-mall.cctv8.co/eper-mall';
//var ApiBaseUrl = 'http://demo-dev.cctv8.co/eper-mall';
//var ApiUrl = 'http://demo-dev.cctv8.co/eper-api';
//var ApiBaseUrl = 'http://localhost:8082/eper-mall';

//本地
// export const ApiBaseUrl ='http://localhost:8082/eper-mall'
// export const ApiUrl ='http://localhost:8082/eper-api'

// 测试
//export const ApiBaseUrl = 'http://mall.h5.demo.test.cctv8.co/eper-mall/api/market'
//export const ApiUrl ='http://mall.h5.demo.test.cctv8.co/eper-api'

//export const  = 'http://mall.h5.demo.test.cctv8.co'

// 协同测试
// export const ApiBaseUrl ='http://192.168.3.52:8080/eper-mall/api/'
// export const ApiUrl ='http://192.168.3.52:8080/eper-api/'

import {url1} from '../api/common.js'

// 正式
//export const ApiBaseUrl ='https://mall.h5.eper.cctv8.co/eper-mall'
//export const ApiUrl ='https://mall.h5.eper.cctv8.co/eper-api'
// export const  ='https://mall.h5.eper.cctv8.co'


const url = {
	api: { //后台数据接口
		dynamicDetail: url1 + "market/dynamic/detail", //动态详情
		dynamicPraise: url1 + "market/dynamic/praise", //动态点赞
		dynamicCancelPraise: url1 + "market/dynamic/cancelPraise", //动态取消点赞
		commentList: url1 + "market/comment/list", //评论列表
		addComment: url1 + "market/comment/add", //新增评论
		replyComment: url1 + "market/comment/reply", //回复评论
		commentPraise: url1 + "market/comment/praise", //回复点赞
		commentCancelPraise: url1 + "market/comment/cancelPraise", //回复取消点赞
		checkout: url1 + "market/order/checkout", //导出订单
		createOrder: url1 + "market/order/create", //创建订单
		orderList: url1 + "market/order/list", //订单列表
		memberUpdateStatus: url1 + "market/order/memberUpdateStatus", //买家修改订单状态
		businessUpdateStatus: url1 + "market/order/businessUpdateStatus", //卖家修改订单状态
		orderDetail: url1 + "market/order/detail", //订单详情
		
	},
	resource: { //网络资源

	}
}

const ajax = {
	getAjax: opt => {
		opt = opt || {};
		opt.url = opt.url || '';
		opt.data = opt.data || null;
		opt.method = opt.method || 'GET';
		opt.header = opt.header || {
			"Content-Type": "application/json",
			"token": uni.getStorageSync('token')
		};
		opt.success = opt.success || function() {};
		opt.fail = opt.fail || function() {};
		opt.complete = opt.complete || function() {};

		uni.request({
			url: opt.url,
			data: opt.data,
			method: opt.method,
			header: opt.header,
			dataType: 'json',
			success: function(res) {
				opt.success(res);
			},
			fail: function(res) {
				opt.fail(res);
			},
			complete: function(res) {
				opt.complete(res);
			}
		});
	},
	postAjax: opt => {
		opt = opt || {};
		opt.url = opt.url || '';
		opt.data = opt.data || null;
		opt.method = opt.method || 'POST';
		opt.header = opt.header || {
			"Content-Type": "application/json",
			"token": uni.getStorageSync('token')
		};
		opt.success = opt.success || function() {};
		opt.fail = opt.fail || function() {};
		opt.complete = opt.complete || function() {};

		uni.request({
			url: opt.url,
			data: opt.data,
			method: opt.method,
			header: opt.header,
			dataType: 'json',
			success: function(res) {
				opt.success(res);
			},
			fail: function(res) {
				opt.fail(res);
			},
			complete: function(res) {
				opt.complete(res);
			}
		});
	}
}

//防止连续点击多次打开页面
var navigateToCount = 0;

function navigateTo(url) {
	if (navigateToCount == 0) {
		navigateToCount = 1;
		uni.navigateTo({
			url: url
		});
		setTimeout(function() {
			navigateToCount = 0;
		}, 1000);
	}
}

const msg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}

const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}

export default {
	url,
	ajax,
	navigateTo,
	msg,
	prePage
};
